//
//  SettingController.swift
//  Biubiubiu
//
//  Created by DevWhan on 2019/5/19.
//  Copyright © 2019 DevWhan. All rights reserved.
//

import Cocoa
import FileKit
//目录
//过滤
//
class SettingController: NSWindowController {

    @IBOutlet weak var ip: NSTextField!
    @IBOutlet weak var size: NSPopUpButton!
    @IBOutlet weak var filter: NSTextField!

    var defaultIP: String = ""
    var defaultFilter: String = ""
    var defaultSize: TargetSize = .normal
    var path: Path!
    
    override func windowDidLoad() {
        super.windowDidLoad()

        self.ip.stringValue = defaultIP
        self.filter.stringValue = defaultFilter
        
        switch self.defaultSize {
        case .small:
            self.size.select(self.size.item(at: 1))
        case .normal:
            self.size.select(self.size.item(at: 0))
        }
        
    }
    
    @IBAction func confirm(_ sender: NSButton) {

        var size = TargetSize.normal
        if let title = self.size.selectedItem?.title, title == "精简"{
            size = .small
        }
        
        if let delete = NSApplication.shared.delegate as? AppDelegate {
        
            let project = Project()
            project.path = path.rawValue
            project.date = Date().timeIntervalSince1970
            project.name = path.fileName
            project.size = size == .normal ? 0 : 1
            
            delete.saveThisProject(project: project)
            delete.toOperationView(project: project, size: size, ip: nil, filterContainString: nil)
        }
        
        self.close()
    }
    
}
